import { WeaLocaleProvider } from 'ecCom';
import { Modal, Popover } from 'antd';
const getLabel = WeaLocaleProvider.getLabel;
const confirm = Modal.confirm;

export default class ReplyItemOps extends React.Component {
	onEdit = () => {
		const { updateState, data } = this.props;
		if (typeof updateState === 'function') updateState({ visible: true, value: data.content, operate: 'edit', editId: data.replyid })
	}
	onOk = () => {
		const { deleteReply, data } = this.props;
		typeof deleteReply === 'function' && deleteReply({ replyid: data.replyid, parentid: data.replymainid });
	}
	onDelete= () => {
		confirm(
			{
				content: getLabel(386316, '确认要删除这条回复吗？'),
				onOk: this.onOk,
			},
		);
	}
	doReply = () => {
		const { updateState, data } = this.props;
		typeof updateState === 'function' && updateState({ visible: true, value: '', operate: 'save', editId: data.replyid });
	}
	onPraiseClick = () => {
		const { onPraiseClick, data, isPraise } = this.props;
		typeof onPraiseClick === 'function' && onPraiseClick(data, !isPraise);
	}
  render() {
		const { hasChild, showTime, currentUser, userid, data, isPraise, users, praise } = this.props;
    return (
			<span className="wea-doc-detail-reply-list-item-child-ops">
				{ !hasChild && !showTime.overtime && currentUser == userid &&
					<span onClick={this.onEdit}><i className="icon-coms-edit" />{getLabel(103, '修改')}</span>
				}
				{ !hasChild && !showTime.overtime && currentUser == userid &&
					<span onClick={this.onDelete}
					><i className="icon-coms-delete" />{getLabel(91, '删除')}</span>
				}
				<span onClick={this.doReply}><i className="icon-coms-New-SMS" />{getLabel(18540, '回复')}</span>
				<span>
					<i className="icon-coms-Good" style={isPraise ? { color: '#ff602f' } : null} onClick={this.onPraiseClick} />
					<Popover ecId={`${this && this.props && this.props.ecId || ''}_Popover@mi9qhi`}
						overlayClassName="wea-doc-detail-top-reply-count-wrap wea-doc-detail-top-reply-count-wrap-right"
						placement="bottomRight"
						content={
						users.length > 0 ?
							<span>
								{
									users.map((user, index) => (
											<span><span dangerouslySetInnerHTML={{ __html: `<a href='javaScript:openhrm(${user.userid});' onclick='pointerXY(event);' style='color: #fff;padding-right: 5px'>${user.userName}</a>` }} /> {users.length - 1 > index ? ', ' : ''}</span>
										))
								}
							</span>
						: `${getLabel(386315, '还没有人点赞哦')} ~`
					}
						trigger="hover"
					>
						<span style={isPraise ? { color: '#ff602f' } : null} className="wea-doc-detail-top-reply-count"> ({praise})</span>
					</Popover>
				</span>
			</span>
    )
  }
}
